package org.crazyrunner.common.view.rss;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.feed.AbstractRssFeedView;

import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Description;
import com.sun.syndication.feed.rss.Item;


public class SampleContentRssView extends  AbstractRssFeedView{

	@Override
	protected void buildFeedMetadata(Map<String, Object> model, Channel feed,
			HttpServletRequest request) {
		
	        feed.setTitle("CrazyRunner Rss");
	        feed.setDescription("CrazyRunner Rss 热点资讯");
	        feed.setLink("http://www.baidu.com");
	}
	
	@Override
	protected List<Item> buildFeedItems(Map<String, Object> model,
			HttpServletRequest request, HttpServletResponse response)throws Exception {
		
			List<Item> rssItems = new ArrayList<Item>();
			for (int i = 0; i < 5; i++) {
            Item n = new Item();
            n.setTitle(new String(("第【"+i+"】条spring Rss测试消息标题").getBytes(),"UTF-8"));
            Description d = new Description();
            d.setValue("第【"+i+"】测试消息内容说明");
            n.setDescription(d);
            n.setLink("http://localhost:8080/springdemo/someurl.html");
            n.setAuthor("作者：疯狂");
            n.setPubDate(new Date());
            rssItems.add(n);
        }
		
        return rssItems;
	}
}
